package com.zengqingfa.interview;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zengqingfa
 * @className ABCTest5
 * @description
 * @create 2022/12/3 11:05
 */
public class ABCTest5 {

    private int num;
    private Lock lock = new ReentrantLock();

    /**
     * 打印ABC
     *
     * @param targetNum
     */
    public void printABC(int targetNum) {
        for (int i = 0; i < 10; ) {
            lock.lock();
            if (num % 3 == targetNum) {
                num++;
                i++;
                System.out.println(Thread.currentThread().getName());
            }
            lock.unlock();
        }

    }


    public static void main(String[] args) throws InterruptedException {
        ABCTest5 abcTest5 = new ABCTest5();
        new Thread(() -> {
            abcTest5.printABC(0);
        }, "A").start();
        new Thread(() -> {
            abcTest5.printABC(1);
        }, "B").start();
        new Thread(() -> {
            abcTest5.printABC(2);
        }, "C").start();
    }


}